package com.scvtc.service.room.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scvtc.domain.ResResult;
import com.scvtc.domain.entity.room.RoomBase;
import com.scvtc.domain.vo.PageVo;
import com.scvtc.mapper.room.RoomBaseMapper;
import com.scvtc.service.room.RoomBaseService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service("RoomBaseService")
public class RoomBaseServiceImpl extends ServiceImpl<RoomBaseMapper, RoomBase> implements RoomBaseService {

    @Override
    public ResResult<PageVo<List<RoomBase>>> getAllInfo(Long current, Long size, RoomBase RoomBase) {

//        // 查询所有信息
//        Page<RoomBase> page = page(new Page<>(current, size),
//                LikeQueryUtil.likeQuery(RoomBase, RoomBase.class)
//                        .lambda()
//        );
        Page<RoomBase> page= getBaseMapper().getAllInfo(new Page<RoomBase>(current, size));

        return ResResult.noMsgSuccess(new PageVo<>(page.getRecords(), page.getTotal()));
    }

    @Override
    public ResResult<?> addOneRoom(RoomBase RoomBase) {
        if (save(RoomBase)){
            return ResResult.success(RoomBase.getId());
        }
        return ResResult.fail();
    }

    @Override
    public ResResult<?> updateRoom(RoomBase RoomBase) {
        if (updateById(RoomBase)){
            return ResResult.success(RoomBase.getId());
        }
        return ResResult.fail();
    }

    @Override
    public ResResult<?> deleteRoom(Long id) {
        if (removeById(id)){
            return ResResult.success();
        }
        return ResResult.fail();
    }

    @Override
    public ResResult<?> deleteMultipleRoom(Long[] ids) {
        if (removeByIds(Arrays.asList(ids))){
            return ResResult.success();
        }
        return ResResult.fail();
    }
}
